//
//  NewsRowView.swift
//  maozzi-rss
//
//  Created by 帽子 on 2020/5/30.
//  Copyright © 2020 帽子. All rights reserved.
//	未读列表 row

import SwiftUI

struct NewsRowView: View {
    @EnvironmentObject var userData: UserData
    var newsItem: NewsItem
    let now = Date()

    var body: some View {
        HStack {
            VStack {
                HStack {
                    Spacer()
                    Text(DateUtil.subtract(
                        from: DateUtil.string2date(
                            dateStr: self.newsItem.pubDate!,
                            format: self.newsItem.dateFormat!),
                        to: self.now
                    ))
                        .font(.footnote)
                        .foregroundColor(.gray)
                        .padding(.trailing)
                }
                Text(self.newsItem.title!)
                    .frame(width: 300, height: 60, alignment: .leading)
                if self.userData.unreadListStyle == 3 {
                    // 三栏
                    Text(self.newsItem.content!)
                        .frame(width: 300, height: 20, alignment: .leading)
                        .font(.subheadline)
                        .foregroundColor(.gray)
                        .lineLimit(nil)
                } else {
                    // 默认都是两栏
                }
            }.padding(.leading)
            Image(systemName: "chevron.right")
                .padding(.trailing)
        }
    }
}

struct NewsRowView_Previews: PreviewProvider {
    static var previews: some View {
        NewsRowView(newsItem: RSSUtil.get()[0])
            .environmentObject(UserData())
    }
}
